//
//  OneSellTableViewCell.m
//  CarHome
//
//  Created by 王建男 on 14-9-23.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "OneSellTableViewCell.h"
#import "DealerListModel.h"

@implementation OneSellTableViewCell

- (void)dealloc
{
    [_label_Sco release];
    [_label_ShortName release];
    [_label_addRess release];
    [_label_Price release];
    [_label_Phone release];
    [_label_Orderrange release];
    [_phone release];
    _label_Sco = nil;
    _label_ShortName = nil;
    _label_addRess = nil;
    _label_Price = nil;
    _label_Orderrange = nil;
    _label_Phone = nil;
    _phone = nil;
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self setBackgroundColor:[UIColor whiteColor]];
        [self creatView];
    }
    return self;
}

- (void)creatView
{
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 140)];
    [imageView setImage:[UIImage imageNamed:@"Sell_Background.png"]];
    [self addSubview:imageView];
    [imageView release];
    //是否为4S店铺
    
    _label_Sco = [[UILabel alloc] initWithFrame:CGRectZero];
    [_label_Sco setTextAlignment:NSTextAlignmentCenter];
    [_label_Sco setFont:[UIFont systemFontOfSize:15]];
    [_label_Sco setTextColor:[UIColor whiteColor]];
    [_label_Sco.layer setCornerRadius:20];
    [_label_Sco setClipsToBounds:YES];
    [self.contentView addSubview:_label_Sco];
    
    //公司名

    _label_ShortName = [[UILabel alloc] initWithFrame:CGRectZero];
    _label_ShortName.textColor = myColor_dark;
    [_label_ShortName setFont:[UIFont systemFontOfSize:18]];
    
    [self addSubview:_label_ShortName];
    
    //地址
    _label_addRess = [[UILabel alloc] initWithFrame:CGRectZero];
    _label_addRess.textColor = myColor_dark;
    [_label_addRess setFont:[UIFont systemFontOfSize:15]];
    [_label_addRess setNumberOfLines:2];
    
    [self addSubview:_label_addRess];
    
    //价格
    _label_Price = [[UILabel alloc] initWithFrame:CGRectZero];
    [_label_Price setTextAlignment:NSTextAlignmentRight];
    [_label_Price setFont:[UIFont systemFontOfSize:20]];
    [self addSubview:_label_Price];
    
    //电话
    _label_Phone = [[UILabel alloc] initWithFrame:CGRectZero];
    
    [self addSubview:_label_Phone];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(210, 115, 40, 20)];
    [button setTitle:@"拨打" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:button];
    
    //售卖地点
    _label_Orderrange = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_label_Orderrange];
}

#pragma mark -
#pragma mark 拨打电话

- (void)buttonAction:(id)sender
{
    NSString *telUrl = [NSString stringWithFormat:@"telprompt:%@", _phone];
    NSURL *url = [[NSURL alloc] initWithString:telUrl];
    [[UIApplication sharedApplication] openURL:url];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    //[_label_Sco setFrame:CGRectMake(0, 0, 40, 40)];
    [_label_ShortName setFrame:CGRectMake(20, 10, self.frame.size.width - 80, 30)];
    [_label_addRess setFrame:CGRectMake(20, 40, self.frame.size.width - 30, 60)];
    [_label_Price setFrame:CGRectMake(_label_ShortName.frame.size.width - 20, 10, 90, 30)];
    [_label_Phone setFrame:CGRectMake(20, 115, 190, 20)];
    [_label_Orderrange setFrame:CGRectMake(260, 115, 80, 20)];
}

#pragma mark -
#pragma mark 为cell设置值

- (void)setOneSell:(DealerListModel *)dealer
{
    [_label_ShortName setText:dealer.shortName];
    [_label_addRess setText:dealer.addRess];
    [_label_Price setText:[NSString stringWithFormat:@"%@%@", dealer.saleprice, @"万"]];
    [_label_Phone setText:[NSString stringWithFormat:@"%@%@",@"电话:", dealer.phone]];
    _phone = [[NSString alloc] initWithFormat:@"%@", dealer.phone];
    
    [_label_Orderrange setText:dealer.orderrange];
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
